package de.hsw.shopify.model.dao.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.hsw.shopify.model.entities.Person;

/**
 * 
 * Die Klasse PersonRowMapper mappt die Ergebnisse von Abfragen aus der
 * Datenbank und speichert sie in Java Objekte
 * 
 */
public class PersonRowMapper {

	private final Log logger = LogFactory.getLog(PersonRowMapper.class);

	public Person mapRow(ResultSet rs) throws SQLException {
		logger.debug("entering personRowMapper");

		Person result = new Person();
		result.setPersonID(rs.getInt("personNr"));
		result.setVorname(rs.getString("vorname"));
		result.setNachname(rs.getString("nachname"));
		result.setEmail(rs.getString("email"));
		result.setKennwort(rs.getString("kennwort"));
		result.setStrasse(rs.getString("strasse"));
		result.setHausnummer(rs.getString("hausnummer"));
		result.setPlz(rs.getInt("plz"));
		result.setOrt(rs.getString("ort"));
		if (rs.getInt("admin") == 1) {
			result.setAdmin(true);
		} else {
			result.setAdmin(false);
		}
		result.setBlz(rs.getInt("blz"));
		result.setKontonummer(rs.getInt("kontonummer"));
		return result;
	}

}
